package com.spike.servlet;

import com.spike.service.DeptService;
import com.spike.service.EmpService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/empDelete")
public class EmpDeleteServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        根据id删除员工
        String id = req.getParameter("id");
        int i = Integer.parseInt(id);
        EmpService empService = new EmpService();
        try {
            int i1 = empService.deleteEmp(i);
            if (i1 > 0) {
                resp.sendRedirect(req.getContextPath() + "/empList");
            }else
                req.setAttribute("msg", "删除失败");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
